This page last changed on Aug 24, 2009 by bluk.

Context Information

In addition to request parameters and entities, there is more request information that can be accessed via request @Context injected variables.

When a resource method is invoked, the runtime injects the @Context variables.

@Path("/resource")
public class Resource {
    @Context
    private HttpHeaders headers;

    @GET
    public void get(@Context UriInfo uriInfo) {
       /* use headers or uriInfo variable here */
    }
}

javax.ws.rs.core.HttpHeaders

HttpHeaders provides methods that allow users to access request headers. A few convenience methods such as #getAcceptableLanguages() and #getAcceptableMediaTypes() provide client preference sorted acceptable responses.

javax.ws.rs.core.UriInfo

UriInfo provides methods so developers can find or build URI information of the current request.

javax.ws.rs.core.SecurityContext

SecurityContext provides access to the security information.

javax.ws.rs.core.Request

Request provides methods for evaluating preconditions and for selecting the best response variant based on the request headers.

javax.ws.rs.core.Providers

Providers allows access to the user and runtime provided MessageBodyReaders, MessageBodyWriters, ContextResolvers, and ExceptionMappers. It is useful for other providers but can sometimes be useful for resource methods and classes.

Document generated by Confluence on Nov 11, 2009 06:57